using System;
using System.Web.Security;
using Castle.MonoRail.Framework;
using ElevatorSpeeches.Framework;

namespace ElevatorSpeeches.CommonCode
{
	public class Security
	{
		
		public static void Login(IRailsEngineContext context, User user)
		{
			FormsAuthenticationTicket ticket = new 
				FormsAuthenticationTicket(2,  user.ID.ToString(), DateTime.Now, DateTime.Now.AddYears(1), true, string.Empty);
			
			string token = FormsAuthentication.Encrypt(ticket);
						
			context.Response.CreateCookie(FormsAuthentication.FormsCookieName, token, DateTime.Now.AddDays(30));			
		}


		private static void RemoveAuthToken(IRailsEngineContext context)
		{
			context.Response.CreateCookie(FormsAuthentication.FormsCookieName, string.Empty);
			context.Response.RemoveCookie(FormsAuthentication.FormsCookieName);
		}

		public static void Logout(IRailsEngineContext context)
		{
			
				RemoveAuthToken(context);				
		}


	}
}
